//
//  BaseTableViewController.swift
//  sinaWeibo
//
//  Created by liii on 16/6/26.
//  Copyright © 2016年 liii. All rights reserved.
//

import UIKit

// 遵守协议
class BaseTableViewController: UITableViewController, VisitorLoginDelegate {
    
    var userLogin = UserAccount.sharedAccount.userLogin
    var visitorView: VisitorLoginView?
    
    override func loadView() {
        
        if userLogin {
            super.loadView()
        } else {
            visitorView = VisitorLoginView()
            view = visitorView
            
//            // 给闭包赋值
//            visitorView?.loginBtnClickBlock = {
//                print("调用了闭包")
//            }
            
            // 成为代理
            visitorView?.visitorDelegate = self
            
            // 设置导航栏全局颜色
//            UINavigationBar.appearance().tintColor = UIColor.orangeColor()
            // 添加到航栏按钮
            navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target: self, action: "userWillLogin")
            navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "userWillRegistor")
        }
    }
    
    // 实现代理方法
    func userWillLogin() {
        // 当点击登录按钮的时候,弹出授权界面
        let navigationVC = UINavigationController(rootViewController: OAuthViewController())
        // 采用modal的方式
        self.presentViewController(navigationVC, animated: true, completion: nil)
    }
    
    func userWillRegistor() {
        print("用户将要注册")
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }
}
